package com.fivesixseven;

import java.util.HashMap;

/**
 * @author ピカチュウ(皮卡啾)
 * @date 2021/7/14 14:12
 * @Description: 567. 字符串的排列
 * <p>
 * 自己想的办法
 */
public class FiveSixSeven {
    public boolean checkInclusion(String s1, String s2) {

        int len1 = s1.length();
        int len2 = s2.length();
        int count1 = 0;
        int count2 = 0;

        HashMap<Character, Integer> map = new HashMap<>();

        if (len1 > len2) {
            return false;
        }

        for (int i = 0; i < len1; i++) {
            count1 += s1.charAt(i) * s1.charAt(i);
            map.put(s1.charAt(i), i);
        }
        System.out.println(count1);


        int start = 0;
        for (int i = 0; i < len2; i++) {

            if (map.containsKey(s2.charAt(i))) {
                int n = 0;
                start = i;
                while (n < len1 && start < len2) {
                    count2 += s2.charAt(start) * s2.charAt(start);
                    System.out.println(s2.charAt(start) + "/count2=" + count2);
                    start++;
                    n++;
                }
                System.out.println("while jie shu ");
                if (count1 == count2) return true;
                else count2 = 0;
            } else System.out.println("w  " + s2.charAt(i));
        }
        return count1 == count2;
    }
}
